/*
 *	Copyright © 2013 Changsha Shishuo Network Technology Co., Ltd. All rights reserved.
 *	长沙市师说网络科技有限公司 版权所有
 *	http://www.shishuo.com
 */

package com.hlingsoft.kkh.action.admin;

import com.hlingsoft.kkh.constant.SystemConstant;
import com.hlingsoft.kkh.dao.*;
import com.hlingsoft.kkh.entity.Admin;

import com.hlingsoft.kkh.entity.Reply;
import com.hlingsoft.kkh.entity.vo.JsonVo;
import com.hlingsoft.kkh.exception.ValidateException;
import com.hlingsoft.kkh.service.*;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 所有action的父类
 */
@Controller
public class AdminBaseAction {

    protected final Logger logger = Logger.getLogger(this.getClass());

    @Autowired
    protected ConfigService configSevice;

    @Autowired
    protected FolderService folderService;

    @Autowired
    protected LikesDao likesDao;

    @Autowired
    protected ShareDao shareDao;

    @Autowired
    protected CollectDao collectDao;

    @Autowired
    protected NotificationDao notificationDao;


    @Autowired
    protected AttachmentService attachmentService;


    @Autowired
    protected AdminService adminService;


    @Autowired
    protected ZhutiService zhutiService;

    @Autowired
    protected CommentsService commentsService;

    @Autowired
    protected InterestDao interestDao;

    @Autowired
    protected ProfessionDao professionDao;

    @Autowired
    protected UserDao userDao;

    @Autowired
    protected EventsDao eventsDao;

    @Autowired
    protected EventCommentsDao eventCommentsDao;

    @Autowired
    protected ImageDao imageDao;

    @Autowired
    protected PushDao pushDao;

    @Autowired
    protected ReportRsDao reportRsDao;

    @Autowired
    protected ReportDao reportDao;

    @Autowired
    protected ReplyDao replyDao;

    @Autowired
    protected FocusDao focusDao;

    @Autowired
    protected FeedbackDao feedbackDao;

    @Autowired
    protected ChatDao chatDao;


    /**
     * 参数校验
     *
     * @param json json数据Bean
     * @throws ValidateException
     */
    protected <T> void validate(JsonVo<T> json) throws ValidateException {
        if (json.getErrors().size() > 0) {
            json.setResult(false);
            throw new ValidateException("有错误发生");
        } else {
            json.setResult(true);
        }
    }

    /**
     * 从session中获得管理员的信息
     *
     * @param request
     * @return
     */
    protected Admin getAdmin(HttpServletRequest request) {
        Admin admin = (Admin) request.getSession().getAttribute(
                SystemConstant.SESSION_ADMIN);
        return admin;
    }
}
